//
//  LFBaseViewController.swift
//  1604_LimitFree
//
//  Created by 千锋 on 16/9/28.
//  Copyright © 2016年 Afei. All rights reserved.
//

import UIKit

class LFBaseViewController: LFNavViewController {

    
    //表格
    var tbView:UITableView?
    
    //数据源数组
    lazy var dataArray = NSMutableArray()
    
    //当前页数
    var curPage: Int = 1
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        
        //表格
        createTableView()
        
        //下载
        downloadData()

    }

    
    func createTableView(){
        automaticallyAdjustsScrollViewInsets = false
        
        tbView = UITableView(frame: CGRectMake(0, 64, KScreenWidth, KScreenHeigh-64-49), style: .Plain)
        tbView?.delegate = self
        tbView?.dataSource = self
        view.addSubview(tbView!)
        
        
        
    }
    
    //加载数据
    //子类重写
    func downloadData(){
        
        print("子类必须重新实现这个方法,\(__FUNCTION__)")
    }
    //下拉刷新
    func loadFirstPage(){
        
        curPage = 1
        downloadData()
        
    }
    //上拉加载更多
    func loadNextPage(){
        curPage += 1
        downloadData()
        
    }
    
    //分页功能
    func addRefresh(){
        
        //下拉刷新
        tbView?.headerView = XWRefreshNormalHeader(target: self, action: "loadFirstPage")
        
        //上拉加载更多
        //这个方法没有风火轮
        //tbView?.footerView = XWRefreshAutoFooter(target: self, action: "loadNextPage")
        tbView?.footerView = XWRefreshAutoNormalFooter(target: self, action: "loadNextPage")
    }
    

  
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

//MARK:UITableView代理
extension LFBaseViewController:UITableViewDelegate,UITableViewDataSource{
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        print("子类必须实现这个方法,\(__FUNCTION__)")
        return 0
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        return UITableViewCell()
    }
}
